// Toast提示系统
function showToast(message, type = 'success', duration = 3000) {
    // 确保toast容器存在
    let container = document.getElementById('toast-container');
    if (!container) {
        container = document.createElement('div');
        container.id = 'toast-container';
        container.className = 'toast-container';
        document.body.appendChild(container);
    }

    const toast = document.createElement('div');
    toast.className = `toast ${type}`;

    const titles = {
        success: '成功',
        error: '错误',
        info: '信息',
        warning: '警告',
        danger: '错误'  // 兼容旧的danger类型
    };

    toast.innerHTML = `
        <div class="toast-header">
            <span class="toast-title">${titles[type] || '提示'}</span>
            <button class="toast-close" onclick="removeToast(this)">&times;</button>
        </div>
        <div class="toast-body">${message}</div>
    `;

    container.appendChild(toast);

    // 触发显示动画
    setTimeout(() => {
        toast.classList.add('show');
    }, 100);

    // 自动移除
    setTimeout(() => {
        removeToast(toast);
    }, duration);
}

function removeToast(element) {
    const toast = element.closest ? element.closest('.toast') : element;
    if (toast) {
        toast.classList.remove('show');
        setTimeout(() => {
            if (toast.parentNode) {
                toast.parentNode.removeChild(toast);
            }
        }, 300);
    }
}

// 显示消息提示（保持兼容性）
function showMessage(message, type = 'success') {
    // 将旧的type映射到新的type
    const typeMap = {
        'danger': 'error',
        'success': 'success',
        'info': 'info',
        'warning': 'warning',
        'error': 'error'
    };
    showToast(message, typeMap[type] || type);
}

// 显示消息提示（保持兼容性）
function showMessage(message, type = 'success') {
    showToast(message, type);
}